recode_demographic_values <- function(all_data, current.year){
  
  all_data$US <- 0
  all_data$US[all_data$Live.in.US == "1"] <- 1
  
  all_data$Education <- as.numeric(all_data$Education)
  all_data$Education[all_data$Education == 1] <- 44
  all_data$Education[all_data$Education == 2] <- 6.5
  all_data$Education[all_data$Education == 3] <- 100
  all_data$Education[all_data$Education == 4] <- 12
  all_data$Education[all_data$Education == 5] <- 14
  all_data$Education[all_data$Education == 6] <- 16
  all_data$Education[all_data$Education == 7] <- 17.5
  all_data$Education[all_data$Education == 8] <- 21
  all_data$Education[all_data$Education == 9] <- 20
  all_data$Education[all_data$Education == 10] <- 19
  all_data$Education[all_data$Education == 11] <- 20
  all_data$Education[all_data$Education == 44] <- 4
  all_data$Education[all_data$Education == 100] <- 10
  
  birth_years <- as.numeric(all_data$Birth.Year)
  birth_years[birth_years == 98] <- 0
  birth_years[birth_years == 99] <- -1
  years <- current.year - (1998 - birth_years)
  all_data$age.years <- years
  
  all_data$income <- NA
  all_data$income[all_data$Salary==1] <- 1500
  all_data$income[all_data$Salary==2] <- 4000
  all_data$income[all_data$Salary==3] <- 6250
  all_data$income[all_data$Salary==4] <- 8750
  all_data$income[all_data$Salary==5] <- 10500
  all_data$income[all_data$Salary==6] <- 11750
  all_data$income[all_data$Salary==7] <- 13750
  all_data$income[all_data$Salary==8] <- 16000
  all_data$income[all_data$Salary==9] <- 18500
  all_data$income[all_data$Salary==10] <- 21000
  all_data$income[all_data$Salary==11] <- 23500
  all_data$income[all_data$Salary==12] <- 27500
  all_data$income[all_data$Salary==13] <- 32500
  all_data$income[all_data$Salary==14] <- 37500
  all_data$income[all_data$Salary==15] <- 42500
  all_data$income[all_data$Salary==16] <- 47500
  all_data$income[all_data$Salary==17] <- 55000
  all_data$income[all_data$Salary==18] <- 67500
  all_data$income[all_data$Salary==19] <- 82500
  all_data$income[all_data$Salary==20] <- 95000
  all_data$income[all_data$Salary==21] <- 105000
  all_data$income[all_data$Salary==22] <- 115000
  all_data$income[all_data$Salary==23] <- 127500
  all_data$income[all_data$Salary==24] <- 142500
  all_data$income[all_data$Salary==25] <- 150000
  all_data$income[all_data$Salary==26] <- NA
  
  all_data$Race[all_data$Race==1] <- "white"
  all_data$Race[all_data$Race==2] <- "black"
  all_data$Race[all_data$Race==3] <- "native american"
  all_data$Race[all_data$Race==4] <- "asian indian"
  all_data$Race[all_data$Race==5 | all_data$Race == 9] <- "japanese"
  all_data$Race[all_data$Race==6] <- "hawaiian"
  all_data$Race[all_data$Race==7] <- "chinese"
  all_data$Race[all_data$Race==8] <- "korean"
  all_data$Race[all_data$Race==10] <- "guamanian"
  all_data$Race[all_data$Race==11] <- "filipino"
  all_data$Race[all_data$Race==12] <- "vietnamese"
  all_data$Race[all_data$Race==13] <- "samoan"
  all_data$Race[all_data$Race==14] <- "other"
  all_data$Race[all_data$Hispanic==1] <- "hispanic"
  
  all_data$race <- NA
  all_data$race[all_data$Race == "white"] <- "white"
  all_data$race[all_data$Race == "black"] <- "black"
  all_data$race[all_data$Race != "white" & all_data$Race != "black"] <- "other"
  
  all_data$female <- NA
  all_data$female[all_data$Gender==2] <- 1
  all_data$female[all_data$Gender==1] <- 0
  
  all_data$liberal <- NA
  all_data$liberal[all_data$Ideology==1] <- 1
  all_data$liberal[all_data$Ideology==2] <- 0
  
  all_data$partyID <- NA
  all_data$partyID[all_data$Party == 1] <- "Democrat"
  all_data$partyID[all_data$Party == 2] <- "Republican"
  all_data$partyID[all_data$Party == 3] <- "Independent"
  
  all_data$English <- as.numeric(all_data$English)
  all_data$English[all_data$English == 2] <- 0
  
  return(all_data)
}

## functions to return standard errors for numeric values
SE <- function(x) sd(na.omit(x))/sqrt(length(na.omit(x)))
## functions to return standard errors for proportions
SE.prop <-function(x) sqrt(mean(na.omit(x))*(1-mean(na.omit(x)))/length(na.omit(x)))

